home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Driver 2.2 Source / THINKProc.c < prev   
C/C++ Source or Header  |  1993-10-23  |  2KB  |  48 lines

  1. /*
  2.  *    THINKProc.c by Pete Resnick. This source file should be compiled in
  3.  *    THINK C in a seperate project as a code resource. The resource type
  4.  *    is defined in driver.c as 'PROC' and the resource ID is defined as 128
  5.  *    in drvrincludes.h. The ID canbe changed if necessary. This code
  6.  *    actually replaces the call to GetResource in THINK C's driver glue.
  7.  *    Instead of the driver DATA resource and multi-segment DCOD resources
  8.  *    being in the driver's resource file, they are detached handles in the
  9.  *    system heap and are literally "tacked on" to the bottom of this piece
  10.  *    of code: attached to the end of the pointer containing *THIS* code is
  11.  *    an array of handles and resource ID's. The code returns the handle to
  12.  *    the correct detached resource.
  13.  */
  14.  
  15. #include "drvrincludes.h"
  16. #include <SetUpA4.h>
  17.  
  18. /*
  19.  *    Global variables are stored at the end of the code segment. With
  20.  *    resRec, we have a zero-filled structure at the end of the code segment
  21.  *    which can server as a marker.
  22.  */
  23. RsrcRec resRec = {nil, 0, 0};
  24.  
  25. pascal Handle main(ResType theTyp, short theID)
  26. {
  27.     Size theSize;
  28.     RsrcRec *resPtr;
  29.     Ptr codePtr;
  30.     
  31.     RememberA0();
  32.     SetUpA4();
  33.     
  34.     /* Get the starting address of the code segment */
  35.     asm { move.l a4, codePtr }
  36.     
  37.     /* Figure out how big the pointer is and start at the end */
  38.     theSize = GetPtrSize(codePtr);
  39.     resPtr = (RsrcRec *)(codePtr + theSize);
  40.     
  41.     /* Look for the handle with the correct resource ID */
  42.     while(((--resPtr)->rsrc != nil) &&
  43.           ((resPtr->id != theID) || (resPtr->typ != theTyp)))
  44.         /* Do nothing */ ;
  45.     RestoreA4();
  46.     return(resPtr->rsrc);
  47. }
  48.